// Package packet
// @Author: zhengqi Wu
// @Description:
// @Version: 1.0.0
// @Date: 2021/4/22 4:12 下午
// @Copyright: MIN-Group；国家重大科技基础设施——未来网络北大实验室；深圳市信息论与未来网络重点实验室
//

const encoding = require("../encoding");

/**
 * IsInterest 判断一个 MINPacket 是否是一个兴趣包
 * @param packet
 * @return {boolean}
 */
function isInterest(packet){
    let packetType = packet.MINPacket.packetType
    if(packetType !== encoding.tlv.ComponentType.TlvIdentifierContentInterest)
        return false

    return packet.ReadOnlyField.getBlockByType(encoding.tlv.ComponentType.TlvNackHeader) === undefined
}

/**
 * IsData 判断一个 MINPacket 是否是一个 Nack
 * @param packet
 * @return {boolean}
 */
function isData(packet){
    let packetType = packet.MINPacket.packetType
    return packetType === encoding.tlv.ComponentType.TlvIdentifierContentData
}

/**
 * IsNack 判断一个 MINPacket 是否是一个 Nack
 * @param packet
 * @return {boolean}
 */
function isNack(packet){
    let packetType = packet.MINPacket.packetType
    if(packetType !== encoding.tlv.ComponentType.TlvIdentifierContentInterest)
        return false

    return packet.ReadOnlyField.getBlockByType(encoding.tlv.ComponentType.TlvNackHeader) !== undefined
}

/**
 * IsCPacket 判断一个 MINPacket 是否是一个 CPacket
 * @param packet
 * @return {boolean}
 */
function isCPacket(packet){
    let packetType = packet.MINPacket.packetType
    return packetType === encoding.tlv.ComponentType.TlvIdentifierCommon
}

module.exports = {
    isCPacket:isCPacket,
    isData:isData,
    isInterest:isInterest,
    isNack:isNack
}